package algorithm.sort.review;

import java.util.Arrays;

public class Quick {
    public static void main(String[] args) {
        int[] arr = {19, 97, 9, 17, 1, 8, 27};
        sort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr, int left, int right) {
        if (left < right) {
            int r = right;
            int l = left;
            int temp = arr[left];
            while(l < r){
                while (arr[r] > temp && l < r){
                    r--;
                }
                if (l == r)
                    break;
                arr[l++] = arr[r];
                while (arr[l]< temp && l<r){
                    l++;
                }
                if (l == r)
                    break;
                arr[r--] = arr[l];
            }
            arr[l] = temp;
            sort(arr,left,l-1);
            sort(arr,l+1,right);
        }
    }

}
